home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / toolkit / vbof_v11 / demophon.cls < prev    next >
Text File  |  1996-03-01  |  7KB  |  261 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Phone"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10. ' the following pertain to being supported by
  11. '   VBOFCollection, VBOFObjectManager and
  12. '   VBOFEventManager
  13. Public ObjectID As Long
  14. Public ObjectChanged As Long
  15. Public ObjectAdded As Long
  16. Public ObjectDeleted As Long
  17. Public ObjectParentCount As Long
  18. Public ObjectManager As VBOFObjectManager
  19.  
  20. ' the following code pertains to the business
  21. '   of the Phone object
  22. Private pvtPhoneNumber As String
  23. Private pvtUsage As String
  24.  
  25. Public Function ObjectSortCompare(Optional SortField As Variant, Optional SortOrder As Variant, Optional CompareObject As Variant) As Long
  26. ' Support the Collection.Sort method
  27. ' Note: use the ObjectManager.ObjectSortCompare
  28. '   method for assistance
  29.  
  30.     Select Case SortField
  31.         Case "PhoneNumber"
  32.             ObjectSortCompare = _
  33.                 ObjectManager.ObjectSortCompare( _
  34.                     Value1:=PhoneNumber, _
  35.                     Value2:=CompareObject.PhoneNumber, _
  36.                     SortOrder:=SortOrder)
  37.         
  38.         Case "FormattedPhoneNumber"
  39.             ObjectSortCompare = _
  40.                 ObjectManager.ObjectSortCompare( _
  41.                     Value1:=FormattedPhoneNumber, _
  42.                     Value2:=CompareObject.FormattedPhoneNumber, _
  43.                     SortOrder:=SortOrder)
  44.         
  45.         Case "Usage"
  46.             ObjectSortCompare = _
  47.                 ObjectManager.ObjectSortCompare( _
  48.                     Value1:=Usage, _
  49.                     Value2:=CompareObject.Usage, _
  50.                     SortOrder:=SortOrder)
  51.     End Select
  52.  
  53. End Function
  54.  
  55.  
  56.  
  57.  
  58. Public Function ObjectDBGridUnboundReadData(Optional DBGrid As Variant, Optional RowBuf As Variant, Optional RowNumber As Variant) As Boolean
  59. ' Populate the DBGrid RowBuf with values from
  60. '   variables within this object
  61. '   (in support of VBOFCollection)
  62. ' Parameter Description:
  63. '   DBGrid:= the DBGrid which is being
  64. '       populated
  65. '   RowBuf:= the current DBGrid RowBuf object
  66. '   RowNumber:= the row number being processed
  67.  
  68.     Dim I As Long
  69.     
  70.     For I = 0 To RowBuf.ColumnCount - 1
  71.         Select Case RowBuf.ColumnName(I)
  72.             Case "PhoneNumber"
  73.                 RowBuf.Value(RowNumber, I) = PhoneNumber
  74.             Case "Usage"
  75.                 RowBuf.Value(RowNumber, I) = Usage
  76.             Case "ObjectID"
  77.                 RowBuf.Value(RowNumber, I) = ObjectID
  78.         End Select
  79.     Next I
  80.  
  81. End Function
  82.  
  83. Public Function ObjectDBGridUnboundAddData(Optional DBGrid As Variant, Optional RowBuf As Variant, Optional NewRowBookmark As Variant) As Boolean
  84. ' Populate the object variables with the values
  85. '   provided by the user in the new row of the
  86. '   DBGrid
  87. '   (in support of VBOFCollection)
  88. '
  89. ' Parameter Description:
  90. '   DBGrid:= the DBGrid which is being
  91. '       populated
  92. '   RowBuf:= the current DBGrid RowBuf object
  93. '   NewRowBookmark:= the row number being processed
  94.  
  95.     Dim I As Long
  96.     
  97.     For I = 0 To RowBuf.ColumnCount - 1
  98.         If Not IsNull(RowBuf.Value(0, I)) Then
  99.             Select Case RowBuf.ColumnName(I)
  100.                 Case "PhoneNumber"
  101.                     PhoneNumber = RowBuf.Value(0, I)
  102.                 Case "Usage"
  103.                     Usage = RowBuf.Value(0, I)
  104.     
  105. ' Note:  Do not initialize the ObjectID.
  106.         
  107.             End Select
  108.         End If
  109.     Next I
  110.     
  111. ' return "OK" status
  112.     ObjectDBGridUnboundAddData = True
  113. End Function
  114.  
  115.  
  116. Public Function ObjectListBoxValue() As String
  117. ' Return a String will represent this object
  118. '   in a ListBox
  119. '   (in support of VBOFCollection)
  120.  
  121.     ObjectListBoxValue = _
  122.         FormattedPhoneNumber
  123.  
  124. End Function
  125.  
  126.  
  127. Private Sub Class_Terminate()
  128.     If Not ObjectManager Is Nothing Then
  129.         ObjectManager.TerminateObject _
  130.             Object:=Me
  131.     End If
  132. End Sub
  133.  
  134.  
  135.  
  136. Public Function ObjectHasChanged()
  137. ' Mark this object as "Changed" and trigger the
  138. '   "Changed" event
  139.  
  140.     ObjectChanged = True
  141.     
  142. #If NoEventMgr = False Then
  143.     If Not ObjectManager Is Nothing Then
  144.         ObjectManager. _
  145.             TriggerObjectEvent _
  146.                 Event:="Changed", _
  147.                 Object:=Me
  148.     End If
  149. #End If
  150.  
  151. End Function
  152.  
  153. Public Function FormattedPhoneNumber() As String
  154. ' Return a displayable, fully formatted
  155. '   version of Me
  156.  
  157.     If Len(PhoneNumber) <= 7 Then
  158.         FormattedPhoneNumber = Format$(PhoneNumber, "000-0000")
  159.     ElseIf Len(PhoneNumber) <= 10 Then
  160.         FormattedPhoneNumber = Format$(PhoneNumber, "(000) 000-0000")
  161.     ElseIf Len(PhoneNumber) = 11 Then
  162.         FormattedPhoneNumber = Format$(PhoneNumber, "0 (000) 000-0000")
  163.     Else
  164.         FormattedPhoneNumber = PhoneNumber
  165.     End If
  166.  
  167. End Function
  168.  
  169.  
  170. Public Function ObjectInitializeFromRecordSet(Optional RecordSet As Variant) As Phone
  171. ' Populate my variables from the RecordSet
  172. '   (in support of VBOFCollection)
  173.  
  174.     On Local Error Resume Next
  175.     
  176.     PhoneNumber = RecordSet("PhoneNumber")
  177.     Usage = RecordSet("Usage")
  178.     
  179.     ObjectID = RecordSet("ObjectID")
  180.  
  181.     Set ObjectInitializeFromRecordSet = Me
  182. End Function
  183.  
  184.  
  185. Public Function ObjectInitializeRecordSet(Optional RecordSet As Variant) As Long
  186. ' Populate the RecordSet with my variables.
  187. '   Do not initialize the ObjectID column.
  188. '   Return any error code encountered.
  189. '   (in support of VBOFCollection)
  190.  
  191.     On Local Error GoTo InitializeRecordSet_SetError
  192.     Err = 0
  193.     
  194.     RecordSet("PhoneNumber") = PhoneNumber
  195.     RecordSet("Usage") = Usage
  196.         
  197. ' Note:  Do not initialize the ObjectID column.
  198.  
  199.     GoTo InitializeRecordSet_SetError
  200.  
  201. InitializeRecordSet_SetError:
  202.     ObjectInitializeRecordSet = Err
  203.     Exit Function
  204. End Function
  205.  
  206.  
  207. Public Function ObjectNewInstanceOfMyClass() As Phone
  208. ' Return a new instance of this class
  209. '   (in support of VBOFCollection)
  210.  
  211.     Set ObjectNewInstanceOfMyClass = New Phone
  212. End Function
  213.  
  214.  
  215. Public Function ObjectEventCallBack(Optional Event As Variant, Optional Object As Variant) As Long
  216. ' Receive the Trigger notification and process
  217. '   accordingly
  218. '
  219. ' Parameters:
  220. '   Event
  221. '       a string which identifies the Event
  222. '       Example: "Changed", "Created", "Deleted"
  223. '   Object
  224. '       the object originating the Event.
  225. '       responds to:
  226. '           TypeName(TriggerObject)
  227. '           TriggerObject.ObjectID
  228. ' (supported by VBOFEventManager)
  229.  
  230. End Function
  231.  
  232.  
  233.  
  234.  
  235.  
  236. Public Function ObjectDataSource() As String
  237. ' Return the Data Source with which this Class is associated
  238. '   (in support of VBOFCollection)
  239.     
  240.     ObjectDataSource = "Phones"
  241. End Function
  242.  
  243.  
  244. Public Property Get PhoneNumber() As String
  245.     PhoneNumber = pvtPhoneNumber
  246. End Property
  247.  
  248. Public Property Let PhoneNumber(aString As String)
  249.     pvtPhoneNumber = aString
  250. '    ObjectHasChanged
  251. End Property
  252.  
  253. Public Property Get Usage() As String
  254.     Usage = pvtUsage
  255. End Property
  256.  
  257. Public Property Let Usage(aString As String)
  258.     pvtUsage = aString
  259. '    ObjectHasChanged
  260. End Property
  261.